<?php

    // +----------------------------------------------------------------------
    // | 主页
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------

    namespace app\controller\store;

    use app\event\ucenter\IpPool;
	use app\model\app\Device;
	use app\event\cms\Advertising as AdvertisingEvent;
	use app\model\cms\Document;
	use app\common\model\SystemConfig;
	use app\model\store\GoodCategory;
	use app\model\store\GoodCategory as CategoryModel;
    use app\pay\model\Payment;
	use app\model\store\Store;
	use app\model\ucenter\User as UserModel;
    use think\facade\Config;
	use app\event\cms\Document as DocumentEvent;
    use app\model\store\StoreFloor as StoreFloorModel;
    use app\model\store\Good as GoodModel;

    class Index extends Common
    {

        /**
         * 商家主页
         * @return mixed|string
         * @author 微尘 <yicmf@qq.com>
         */
        public function index()
        {

            return 'ok';
//			$store = Device::with(['users' => function($query){
//				$query->wherePivot('status',1)->wherePivot('create_time','>','2022-07-24');
//			}])->select();
//
//			dump($store->toArray());
//			return 1;
//			halt($store);
			$banners = AdvertisingEvent::lists(1);

            $floor =  StoreFloorModel::with('cover')->where('status',1)->where('location',0)->order('sort ASC')->select()->toArray();

			$cates = GoodCategory::where('status',1)->where('parent_id',0)->select();
            $floors  =[];
            foreach ($floor as $item) {
                $item['keyword1'] = explode('|',$item['keyword1']);
                $item['keyword2'] = explode('|',$item['keyword2']);
//                if ($item['good_ids'])
//                {
//                    $item['goods'] = GoodModel::scope('sale')->where('id|sn','in',$item['good_ids'])->select();
//                }else{
                    $item['goods'] = GoodModel::scope('sale')->where('cover_id','>',0)->limit(6)->orderRand()->select();
//                }
                if (count($item['goods']) >=6)
                {
                    $floors[] = $item;
                }
            }
//            $recommend = GoodModel::scope('sale')->orderRaw('rand()')->limit(6)->select();
            $recommend = AdvertisingEvent::lists(4);
			if ($this->user)
			{
				$this->assign('wait_send',$this->user->orders()->where('status',2)->count());
				$this->assign('wait_pay',$this->user->orders()->where('status',1)->count());
				$this->assign('wait_confirm',$this->user->orders()->where('status',3)->count());
				$this->assign('wait_pj',$this->user->orders()->where('status',5)->where('evaluation_status','<>',1)->count());
			}
			$this->assign('recommend',$recommend);
			$this->assign('recommend_l',count($recommend));
			$this->assign('banners',$banners);
			$this->assign('floors',$floors);
			$this->assign('cates',$cates);
			return  $this->fetch();
        }

        public function blog()
        {
			$doc = new DocumentEvent();
			$data = $doc->detail($this->request->param());
			if ($data['code'] == 0)
			{

				$this->assign('blogs',Document::where('status',1)->select());
				$this->assign('data',$data['data']);
				return  $this->fetch();
			}else{
				$this->error('文章不存在');
			}
        }

    }
